package com.kingdee.eas.custom.hr.affair.contract.client;

import java.math.BigDecimal;
import java.util.Date;

import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.eas.basedata.org.OrgType;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.custom.common.Constants;
import com.kingdee.eas.custom.hr.affair.contract.ShortContractEvalEntryInfo;
import com.kingdee.eas.custom.hr.affair.contract.ShortContractEvalFactory;
import com.kingdee.eas.custom.hr.affair.contract.StatusEnum;
import com.kingdee.eas.framework.FrameWorkUtils;
import com.kingdee.eas.hr.base.client.IHRF7CommonRegister;
import com.kingdee.eas.hr.emp.EmployeeContractInfo;
import com.kingdee.jdbc.rowset.IRowSet;

public class ShortContractEvalEditUIBiz extends ContractEvalEditUIBiz {

	@Override
	protected IObjectValue createNewDetailData(PersonInfo person) {
		ShortContractEvalEntryInfo info = new ShortContractEvalEntryInfo();
		info.setNumber(person.getNumber());
		info.setName(person.getName());
		if (person.getDuty() != null) {
			info.setJob(person.getDuty().getName());
		}
		if (person.getGrade() != null) {
			// info.setGrand(person.getGrade().getName());
		}
		info.setJoinDate(person.getJoinJobDate());
		info.setGender(person.getGender());
		info.setBirthday(person.getBirthday());

		if (person.getChildRearing() != null) {
			info.setIsChild(person.getChildRearing().getName());
		}
		info.setAddress(person.getNowAddr());

		if (person.getAttendanceCode() != null) {
			info.setAttendCode(person.getAttendanceCode().getName());
		}

		if (person.get("CONTRACT") != null) {
			EmployeeContractInfo contract = (EmployeeContractInfo) person
					.get("CONTRACT");
			info.setContract(contract.getId().toString());
		}
		info.setPerson(person);
		info.setLate(((BigDecimal) person.get("DAILY_LATE")).toString());
		info.setSickLeave(((BigDecimal) person.get("LEAVE_SICK")).toString());
		info.setAbsence(((BigDecimal) person.get("DAILY_ABSENCE")).toString());

		info.setAward(person.get("JL").toString());
		info.setDiscipline(person.get("CF").toString());
		
		if (person.get("AVG_GRADE") != null) {
			BigDecimal b = new BigDecimal(person.get("AVG_GRADE").toString());
			info.setEvalCoefficient(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
		}
		
		info.setStatus(StatusEnum.NOT);
		info.setEffectDate(new Date());
		return info;
	}

	@Override
	public void registerContextChangeF7(IHRF7CommonRegister register) {
		super.registerContextChangeF7(register);
		register
				.registerAdminByOrgRangePromptBox(((ShortContractEvalEditUI) this.ctx
						.getUI()).prmtAdminOrg);
	}

	protected IRowSet execQuery(Date from, Date to) throws Exception {

		FilterInfo filter = FrameWorkUtils.getF7FilterInfoByAuthorizedOrg(
				OrgType.Admin, "T2.CFDeptID", false);

		FilterInfo fi = new FilterInfo();
		fi.getFilterItems().add(
				new FilterItemInfo("T1.FEndDate", from,
						CompareType.GREATER_EQUALS));
		fi.getFilterItems().add(
				new FilterItemInfo("T1.FEndDate", to, CompareType.LESS_EQUALS));
		fi.getFilterItems().add(
				new FilterItemInfo("T2.FEmployeeClassifyID",
						Constants.EMPLOYEE_CLASSIFY_SHORT));
		fi.setMaskString("#0 and #1 and #2");
		filter.mergeFilter(fi, "and");

		return ShortContractEvalFactory.getRemoteInstance().getPersonContract(
				filter);
	}
}